package com.raysdata.smartcity.mail;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
/**
 * Created by liuxin on 2016/12/9.
 */
public class SendEmail {
    public static void SendEmail(String[] addr,String subject,String msg) {
        String smtp="smtp.exmail.qq.com";
        String emailID="notification@raysdata.com";
        String emailPw="Raysdata@2016!";
        if (msg != null && msg.length() > 0 && addr != null
                && addr.length > 0) {
            SimpleEmail email = new SimpleEmail();
            email.setCharset("UTF-8");
            email.setHostName(smtp); // 邮件服务器的smtp信息
            email.setAuthentication(emailID, emailPw); // 校验信息，邮箱的用户名和密码

            try {
                email.setFrom(emailID, emailID);

                for (String zf : addr) {
                    email.addTo(zf);
                }
                email.setSubject(subject);
                email.setMsg(msg);
                email.send();
                // 释放资源
                email = null;
            } catch (EmailException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        SendEmail sendEmail = new SendEmail();
        sendEmail.SendEmail(new String[]{"123564081@qq.com"},"邮件标题","邮件内容");
    }
}
